1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10 using System.Data.SqlClient;
11
12 namespace SoftQuanLyNhaHang.Views
13 {
14 public partial class uctSearchNhanVien : UserControl
15 {
16 public uctSearchNhanVien()
17 {
18 InitializeComponent();
19 }
20 void loadcontrol()
21 {
22 cmbFind.Items.Clear();
23 cmbFind.Items.Add("Id Nhân Viên");
24 cmbFind.Items.Add("Tên Nhân Viên");
25 }
26 private void uctSearchNhanVien_Load(object sender, EventArgs e)
27 {
28 cmbFind.Text = "Id Nhân Viên";
29 loadcontrol();
30 }
31
32 private void btnFind_Click(object sender, EventArgs e)
33 {
34 if (txtFind.Text == "")
35 MessageBox.Show("Hãy nhập vào ô tìm kiếm", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
36 else
37 {
38 if (cmbFind.Text == "Id Nhân Viên")
39 {
40 string _idNhanVien= txtFind.Text.ToString();
41 DataTable dt = new DataTable();
42 dt = Controllers.NhanVienCtrl.FillDataSet_getSearchNVbyId(_idNhanVien).Tables[0];
43
44 if(dt.Rows.Count>0)
45 {
46 dgvDanhSachNV.DataSource = dt;
47 }
48 else
49 {
50 MessageBox.Show("Id " +txtFind.Text+ " Không có trong dữ liệu", "Thông báo",MessageBoxButtons.OK,MessageBoxIcon.Information);
51 }
52 }
53 else
54 {
55 string _tenFind = txtFind.Text.ToString();
56 DataTable dt = new DataTable();
57 dt = Controllers.NhanVienCtrl.FillDataSet_FindNVByTen(_tenFind).Tables[0];
58
59 if (dt.Rows.Count > 0)
60 {
61 dgvDanhSachNV.DataSource = dt;
62 }
63 else
64 {
65 MessageBox.Show("Tên " + txtFind.Text + " Không có trong dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
66 }
67 }
68 }
69
70 }
71
72 private void txtFind_TextChanged(object sender, EventArgs e)
73 {
74 if (cmbFind.Text == "Id Nhân Viên")
75 {
76 string _idNhanVien = txtFind.Text.ToString();
77 DataTable dt = new DataTable();
78 dt = Controllers.NhanVienCtrl.FillDataSet_getSearchNVbyId(_idNhanVien).Tables[0];
79 dgvDanhSachNV.DataSource = dt;
80 }
81 else
82 {
83 string _tenFind = txtFind.Text.ToString();
84 DataTable dt = new DataTable();
85 dt = Controllers.NhanVienCtrl.FillDataSet_FindNVByTen(_tenFind).Tables[0];
86 dgvDanhSachNV.DataSource = dt;
87 }
88 }
89
90 }
91 }